package com.chance.cc.crawler.development.bootstrap.weibo.tie;

import com.alibaba.fastjson.JSON;
import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRecord;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import org.apache.commons.lang3.time.DateUtils;
import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;

import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRecordFilter.key;
import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRequestType.*;

/**
 * @ClassName weibo
 * @Description TODO
 * @Author songding
 * @Date 2021/10/26 22:55
 * @Version 1.0
 **/
public class WeiboTeStart {
    private static final String domain = "weibo";
    private static final String site = "tie";
    public static void main(String[] args) {
        limit();
    }
    private static Proxy proxy = new Proxy();
    static {
        //代理配置
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("HL89Q19E86E2987D");
        proxy.setPassword("71F33D94CE5F7BF2");
    }
    public static void limit(){
//        String url = "https://weibo.com/1698264705/KzH6W9XJb";
      /*  String url = "http://weibo.com/6405308384/KyrnXa0Ci";*/
        String url ="http://weibo.com/7374982256/Ky5xT8wAF";
      //  String url = "https://weibo.com/ajax/statuses/buildComments?is_reload=1&id=4682929550657627&is_show_bulletin=2&is_mix=0&max_id=4682938971325292&count=20&uid=7492801172";
//        String mid = "4685072022374549";
       String mid = "4681244732031905";
       // String mid = "4687229753233284";

        CrawlerRequestRecord requestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpUrl(url)
                .httpConfig(HttpConfig.me(domain))
                .releaseTime(System.currentTimeMillis())
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .proxy(proxy)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(59*24,null))
                .build();
        requestRecord.tagsCreator().bizTags().addCustomKV("mid",mid);
        requestRecord.tagsCreator().bizTags().addDomain(domain);
        requestRecord.tagsCreator().bizTags().addSite(site);

        CrawlerRecord filterRecord = new CrawlerRecord();
        filterRecord.setFilter(key);                                       //评论采集指定时间过滤条件
//        filterRecord.addFilterInfo(FilterUtils.dateRangeFilterInfo(24 *100,new long[]{1630425600000l,1633017599000l}));
        filterRecord.addFilterInfo(FilterUtils.memoryFilterKeyInfo(domain));
        requestRecord.tagsCreator().bizTags().addCustomKV("comment_record_filter_info", JSON.toJSONString(filterRecord));



        //关键词
        CrawlerRequestRecord keywordRecord = CrawlerRequestRecord.builder()
                .startPageRequest("keyword",turnPageItem)
                .httpUrl("")
                .requestLabelTag(supportSource)
                .requestLabelTag(internalDownload)
                .build();

        DevCrawlerController.builder()
                .triggerInfo(domain,domain,System.currentTimeMillis(),domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline()
                .fileResultPipeline("F:\\chance_log\\weibo\\tie.log",false)
                .requestRecord(requestRecord)
                //.supportRecord(keywordRecord)
                .build("com.chance.cc.crawler.development.scripts.weibo.tie")
                .start();
    }
    @Test
    public void tt(){
        String dt="Thu Sep 16 16:05:13 +0800 2021";
        SimpleDateFormat sdf1= new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
        SimpleDateFormat sdf2= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Long  time = 0l;
        try {
            System.out.println(sdf2.format(sdf1.parse(dt)));
            time = DateUtils.parseDate(sdf2.format(sdf1.parse(dt)),"yyyy-MM-dd HH:mm:ss").getTime();
            System.out.println(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }
}
